<?php

/**
 * MLEPP - ManiaLive Extending Plugin Pack
 * 
 * -- MLEPP Plugin --
 * @name Random Message
 * @date 04-01-2011
 * @version r851
 * @website mlepp.trackmania.nl
 * @package MLEPP
 * 
 * @author Max "TheM" Klaversma <maxklaversma@gmail.com>
 *         Petri "reaby" Järvisalo <petri.jarvisalo@mbnet.fi> 
 *         Guy "Knutselmaaster" Van Der Zel <knutselmaaster@gmail.com>
 * @copyright 2010 - 2011
 * 
 * ---------------------------------------------------------------------
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * ---------------------------------------------------------------------
 * You are allowed to change things or use this in other projects, as
 * long as you leave the information at the top (name, date, version,
 * website, package, author, copyright) and publish the code under
 * the GNU General Public License version 3.
 * ---------------------------------------------------------------------
 */

namespace ManiaLivePlugins\MLEPP\RandomMessage;

use ManiaLive\Utilities\Console;
use ManiaLive\Utilities\String;
use ManiaLive\DedicatedApi\Connection;
use \ManiaLive\PluginHandler\PluginHandler;

use ManiaLivePlugins\MLEPP\Core\Core;
use ManiaLivePlugins\MLEPP\Core\Mlepp;

class RandomMessage extends \ManiaLive\PluginHandler\Plugin {
	protected $tick;
	public static $type = 'endChallenge';
	public static $delay = 180;
	public static $infoname = '$ff3[$o$f00INFO$z$ff3$s]';
	public static $infocolor = '$z$ae0$s';
	public static $messages = array('All windows can be maximized, and minimized to the taskbar. Like in operating systems, more than one window can be kept open like this.',
									'For more information about $fffMLEPP$ae0, please visit: $fff$lhttp://mlepp.trackmania.nl$l$ae0!',
									'Please don\'t sound your horn throughout the entire track!');
    
    /**
     * onInit()
     * Function called on initialisation of ManiaLive.
     * 
     * @return void
     */
    
	function onInit() {               
		$version = 851;
		$this->setVersion($version);
        $this->setPublicMethod('getVersion');   
		$this->tick = 0;

        //ML Repository
        if(Core::RepositoryId != null){
            $this->setRepositoryId(Core::RepositoryId);
            $this->setRepositoryVersion(Core::RepositoryVersion);
        }
	}
    
    /**
     * onLoad()
     * Function called on loading of ManiaLive.
     * 
     * @return void
     */
    
	function onLoad() {
		$this->enableDedicatedEvents();
		$this->enableTickerEvent();
         Console::println('['.date('H:i:s').'] [MLEPP] Plugin: RandomMessage r'.$this->getVersion().' by TheM, reaby & Knutselmaaster.');
		 if(self::$type == "delay" || self::$type == "endChallenge") { 
		 
		 } else {
			 Console::println('['.date('H:i:s').'] [Random Message] Warning: Check your config.ini, the type should be either "delay" or "endChallenge" !');
		}
	}
    
	/**
	 * onReady()
     * Function called when ManiaLive is ready loading.
	 * 
	 * @return void
	 */
	
	function onReady() {
		$pluginHandler = PluginHandler::getinstance();
		$plugins = $pluginHandler->getLoadedPluginsList();

		foreach($plugins as $plugin) {
			list($author,$plugin) = explode('\\',$plugin);
			if($author == "Standard") {
				switch($plugin) {
					case 'Dedimania':
						self::$messages[] = 'Use $o$ea0$i/dedimania ' . self::$infocolor . ' to see the online world record for the current track.';
					break;	
				}
			}	if($author == "oliverde8") {
				switch($plugin) {
					case 'HudMenu':
						self::$messages[] = 'The $o$ea0$iMenu ' . self::$infocolor . ' button contains clickable versions of all commands that are available on this server.';
					break;	
				}
			}						
			if($author == "MLEPP") {
				switch($plugin) {
					case 'Admin':
						self::$messages[] = 'Use $o$ea0$i/players ' . self::$infocolor . ' to see the logins of all players on this server.';
					break;
					case 'ChallengeWidget':
						self::$messages[] = 'The ChallengeWidget displays the author time on the present track.';
					break;
					case 'ChatEmotes':
						self::$messages[] = 'This server has many commands to ease communication, like $o$ea0$i/hi ' . self::$infocolor . ', $o$ea0$i/lol ' . self::$infocolor . ' and $o$ea0$i/gg';
						self::$messages[] = 'You can use the chat emotes in combination with a login to show nicknames, for example $o$ea0$i/nl  $ilogin$i';
						self::$messages[] = 'You can use the chat emotes in combination with a text, for example $o$ea0$i/hi text goes here ' . self::$infocolor . ' and $o$ea0$i/hi  $ilogin$i  text goes here ' . self::$infocolor . '.';
					break;
					case 'ChatLog':
						self::$messages[] = 'Use $o$ea0$i/chatlog ' . self::$infocolor . ' to read back what has been written in the chat recently.';
					break;
					case 'ChatMe':
						self::$messages[] = 'Use $o$ea0$i/me text goes here ' . self::$infocolor . ' to make a chatmessage expressing your current state. (ie $o$ea0$i/me is winning ' . self::$infocolor . ' )';
						self::$messages[] = 'Use $o$ea0$i/me text goes here  $ilogin$i ' . self::$infocolor . ' to make a chatmessage using 2 nicknames. (ie $o$ea0$i/me is wishing you goodnight,  $ilogin$i  ' . self::$infocolor . ' )';
					break;
					case 'Communication':
						self::$messages[] = 'Use $o$ea0$i/players ' . self::$infocolor . ' to find the login of another player and $o$ea0$i/t invite  $ilogin$i ' . self::$infocolor . ' to invite him in a private chat channel.';
						self::$messages[] = 'Use $o$ea0$i/r ' . self::$infocolor . ' to send a new message to the person that you sent your last private message to.';
						self::$messages[] = 'Use $o$ea0$i/t invite  $ilogin$i  ' . self::$infocolor . ' to create a private chat channel and/or invite someone to join.';
						self::$messages[] = 'Use $o$ea0$i/t text goes here ' . self::$infocolor . ' to send a message in the private channel that you joined.';
						self::$messages[] = 'Use $o$ea0$i/t leave ' . self::$infocolor . ' to leave a private chat channel.';
					break;
					case 'Core':
						self::$messages[] = 'For more information about $fffMLEPP ' . self::$infocolor . 'please visit: $fff$lhttp://mlepp.trackmania.nl$l' . self::$infocolor . '!';
						self::$messages[] = 'For help with $fffMLEPP ' . self::$infocolor . 'commands, use $o$ea0$i/<commandname> help ' . self::$infocolor . '!';
					break;
					case 'CustomChat':
						self::$messages[] = 'The CustomChat plugin filters out ugly things from the chat and can indicate who are admins and operators.';
					break;
					case 'DonateCoppers':
						self::$messages[] = 'Do you like our server? Please donate some coppers!';
					break;
					case 'ForceMusics':
						self::$messages[] = 'Use $o$ea0$i/mlist ' . self::$infocolor . ' to see the songs on this server, and click on the names to add songs to the jukebox.';
						self::$messages[] = 'Use $o$ea0$i/musicbox  $inumber$i ' . self::$infocolor . ' to add the corresponding song in the mlist to the musicbox.';
						self::$messages[] = 'Click on the music widget to open the music list and add a song by clicking on it\'s title.';
					break;
					case 'IdleKick':
						self::$messages[] = 'This server forces inactive players into spectator, and eventually kicks them. Use spec when going afk please.';
					break;
					case 'Jukebox':
						self::$messages[] = '$o$ea0$i/list help ' . self::$infocolor . ' gives you an overview of the different ways to find specific tracks on this server.';
						self::$messages[] = 'Use $o$ea0$i/list ' . self::$infocolor . ' to see the tracks on this server, and click on the names to add tracks to the jukebox.';
						self::$messages[] = 'Use $o$ea0$i/jukebox list ' . self::$infocolor . ' to see the tracks in the jukebox.';
						self::$messages[] = 'Use $o$ea0$i/list rank  $inumber$i ' . self::$infocolor . ' to find the tracks where you have a certain rank.';
						self::$messages[] = '$o$ea0$i/list first  $inumber$i  ' . self::$infocolor . ' shows you all tracks where your record is within the first <number> of records. You can also use $o$ea0$i/list nofirst <number>' . self::$infocolor . ' to see all the other tracks.';
						self::$messages[] = 'Use $o$ea0$i/list shorter  $iseconds$i  ' . self::$infocolor . ' to find the tracks that are shorter than a certain number of seconds.';
						self::$messages[] = 'Use $o$ea0$i/list longer  $iseconds$i  ' . self::$infocolor . ' to find the tracks that are longer than a certain number of seconds.';
						self::$messages[] = 'With $o$ea0$i/list tmx_type  $itype$i  ' . self::$infocolor . ' you can find all tracks of a specific type. The types are Race, Puzzle, Platform, Stunts and Shortcut.';
						self::$messages[] = 'With $o$ea0$i/list tmx_dif  $idifficulty$i  ' . self::$infocolor . ' you can find all tracks of a specific difficulty. The difficulties are Beginner, Intermediate, Expert and Lunatic.';
						self::$messages[] = 'With $o$ea0$i/list tmx_style  $istyle$i  ' . self::$infocolor . ' you can find all tracks of a specific style. The styles are Normal, Stunt, Maze, Offroad, Laps, Fullspeed, Lol, Tech, Speedtech, RPG and Presforward.';
						self::$messages[] = 'Use $o$ea0$i/list nofinish ' . self::$infocolor . ' to see a list with the tracks on this server that you haven\'t finished yet.';
						self::$messages[] = 'You can search tracks with the $o$ea0$i/list  $itrackname$i  ' . self::$infocolor . ' command. You can also use a part of the name.';
						self::$messages[] = 'You can search tracks with the $o$ea0$i/list  $iauthorname$i  ' . self::$infocolor . ' command. You can also use a part of the name.';
						self::$messages[] = 'On United servers, you can find all tracks from a specific environment with the $o$ea0$i/list env  $ienvironment$i  ' . self::$infocolor . ' command. Possible environments are Bay, Coast, Speed, Island, Rally, Snow and Stadium.';
						self::$messages[] = 'Find tracks where you set a good rec with the $o$ea0$i/list goldtime ' . self::$infocolor . ' command. You can also use $o$ea0$iauthortime' . self::$infocolor . ' , $o$ea0$isilvertime ' . self::$infocolor . ' and $o$ea0$ibronzetime ' . self::$infocolor . '.';
						self::$messages[] = 'Find tracks where you haven\'t set a good rec with the $o$ea0$i/list nogoldtime ' . self::$infocolor . ' command. You can also use $o$ea0$inoauthortime' . self::$infocolor . ' , $o$ea0$inosilvertime ' . self::$infocolor . ' and $o$ea0$inobronzetime ' . self::$infocolor . '.';
					break;
					case 'Karma':
						self::$messages[] = 'Use $o$ea0$i--' . self::$infocolor . ' , $o$ea0$i-' . self::$infocolor . ' , $o$ea0$i+' . self::$infocolor . ' , $o$ea0$i++ ' . self::$infocolor . ' and ' . self::$infocolor . '$o$ea0$i+++ ' . self::$infocolor . ' to give your opinion about the current track.';
						self::$messages[] = 'Please vote for this track to express your opinion.';
					break;
					case 'LocalRecords':
						self::$messages[] = 'Use $o$ea0$i/recs ' . self::$infocolor . ' to see the local records on the current track.';
					break;
					case 'Rankings':
						self::$messages[] = 'Use $o$ea0$i/top100 ' . self::$infocolor . ' to see the 100 best ranked players with their statistics.';
						self::$messages[] = 'Use $o$ea0$i/rank ' . self::$infocolor . ' to see your actual server rank and your average.';
					break;
					case 'ServerInfo':
						self::$messages[] = '$o$ea0$i/serverinfo ' . self::$infocolor . ' gives information about this server: Who is running it, links to other servers, the available commands and the installed plugins.';
					break;
					case 'ServerMail':
						self::$messages[] = 'Use $o$ea0$i/mail  $ilogin$i  text goes here  ' . self::$infocolor . ' to send a mail to someone, the mail will be stored on the server and can be read anytime.';
						self::$messages[] = 'Use $o$ea0$i/mail admin text goes here  ' . self::$infocolor . ', you will get a token, enter the token and your mail will be sent to all admins.';
						self::$messages[] = '$o$ea0$i/mail read ' . self::$infocolor . ' opens your mailbox, where you can read and manage your received mail.';
						self::$messages[] = 'Send yourself a mail if you want to make a memo, it will be safe in your mailbox.';
					break;
					case 'TmxInfo':
						self::$messages[] = 'Click the TMX logo to see more information about the current track.';
						self::$messages[] = 'If you like this track, click the TMX logo to download or award it.';
						self::$messages[] = 'Press restart or respawn to load the track image in the TMX-Info window.';
					break;
					case 'Votes':
						self::$messages[] = 'Use $o$ea0$i/skip ' . self::$infocolor . ' to start a vote to go directly to the next track.';
						self::$messages[] = 'Use $o$ea0$i/restart ' . self::$infocolor . ' to start a vote to replay a track.';
						self::$messages[] = 'You can see the statistics of a running vote in the vote widget in the top of the screen.';
					break;
					case 'Widgets':
						self::$messages[] = 'Some of the widgets automatically hide at first checkpoints.';
						self::$messages[] = 'Click the widget button to toggle the hide function. Yellow is Autohide, Green is Always visible and Red is Hidden.';
					break;

				}
			}
		}
	}

	/**
	 * onTick()
     * Function called every second, provides the delay messages.
	 * 
	 * @return void
	 */
     
	function onTick() {
		if(self::$type == 'delay') {
			if($this->tick != (self::$delay-1)) {
				$this->tick++;
			} else {
				$this->tick = 0;
				$msgnum = rand(0, (count(self::$messages)-1) );
				$message = self::$infoname . self::$infocolor . self::$messages[$msgnum];
				$this->connection->chatSendServerMessage($message);
			}
		}
	}
    
	/**
	 * onEndChallenge()
     * Function called on end of challenge, providing the end of challenge messages.
	 * 
	 * @param mixed $rankings
	 * @param mixed $challenge
	 * @param mixed $wasWarmUp
	 * @param mixed $matchContinuesOnNextChallenge
	 * @param mixed $restartChallenge
	 * @return void
	 */
    
	function onEndChallenge($rankings, $challenge, $wasWarmUp, $matchContinuesOnNextChallenge, $restartChallenge) {
		if(self::$type == 'endChallenge') {
			$msgnum = rand(0, (count(self::$messages)-1));
			$message = self::$infoname . self::$infocolor . self::$messages[$msgnum];
			$this->connection->chatSendServerMessage($message);
		}
	}
}
?>